import 'package:dy_download_utils/controller_dy.dart';
import 'package:flutter/services.dart';

const String MESSAGE_SEND_DY_URL = "MESSAGE_SEND_DY_URL";

class BtChannelManager {
  static const _batteryChannelName = "com.ug1yk.dy_download"; // 1.方法通道名称

  static final _instance = BtChannelManager._();

  factory BtChannelManager.getInstance() => _instance;

  MethodChannel? _btChannel;

  BtChannelManager._() {
    _btChannel = MethodChannel(_batteryChannelName);
  }

  void init() {}

  void initMessageHandler() {
    _btChannel!.setMethodCallHandler((call) async {
      String medthodName = call.method;
      String arguments = call.arguments;

      switch (medthodName) {
        case MESSAGE_SEND_DY_URL:
          //todo 解析发射器连接状态
          try {
            // print('收到分享： $arguments');
            DyController.to.shareTextLive.value = arguments;
            DyController.to.shareTextLive.refresh();
          } catch (e) {}
          break;
      }
    });
  }
}
